/**
 * File: CurtainRollingFileAppender.java
 * Created by: mhaimel
 * Created on: Nov 26, 2010
 * CVS:  $Id: CurtainRollingFileAppender.java 1.0 Nov 26, 2010 11:12:20 AM mhaimel Exp $
 */
package uk.ac.ebi.curtain.utils;

import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.log4j.RollingFileAppender;
import org.apache.log4j.spi.LoggingEvent;

/**
 * @author mhaimel
 *
 */
public class CurtainRollingFileAppender extends RollingFileAppender {
	
	
	@Override
	public void setFile(String file) {
		super.setFile(file);
		String computername="localhost";
		 try {
			computername = InetAddress.getLocalHost().getHostName();
		} catch (UnknownHostException e) {
			// ignore error
		}
		String pid = ManagementFactory.getRuntimeMXBean().getName();
		// 14589@sunny.beach
		if(pid.contains("@")){
			int idx = pid.indexOf("@");
			pid = pid.substring(0, idx);
		}
		String type = System.getProperty("curtain.pipeline.type", "");
		 
		this.fileName = "curtain-"+type+"_"+computername+"-"+pid+"-"+this.fileName;
	}
	
	@Override
	protected void subAppend(LoggingEvent event) {
		super.subAppend(event);
	}
	
	@Override
	protected boolean checkEntryConditions() {
		return super.checkEntryConditions();
	}
	
}
